package com.tanhua.manage.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanhua.manage.domain.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface LogMapper extends BaseMapper<Log> {

    /**
     * 查询今日注册用户数、登录数
     *
     * @param now
     * @param type
     * @return
     */
    @Select("select count(*) from tb_log where log_time = #{now} and type = #{type}")
    Long queryNumsByType(@Param("now") String now, @Param("type") String type);

    /**
     * 查询活跃用户数
     *
     * @param now
     * @return
     */
    @Select("select count(DISTINCT user_id) from tb_log where log_time = #{now}")
    Long queryNumsByDate(@Param("now") String now);

    /**
     * 查询次日留存数
     * @param now
     * @param yes
     * @return
     */
    @Select("select count(DISTINCT user_id) from tb_log where log_time = #{now} " +
            "in (select user_id from tb_log where log_time = #{yes} and type = '0102') ")
    Long queryRetention1d(@Param("now") String now, @Param("yes") String yes);
}